home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / xlib05.zip / DEMO1.C < prev    next >
C/C++ Source or Header  |  1993-08-27  |  22KB  |  553 lines

  1. /* VERY QUICK AND ULTRA-DIRTY DEMO USING XLIB */
  2.  
  3. /* Simple Demo of MODE X Split screen and panning  */
  4. /* Compile using Turbo C and Tasm                  */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <conio.h>
  9. #include <ctype.h>
  10. #include <alloc.h>
  11. #include <dos.h>
  12. #include "Xlib_all.h"
  13.  
  14. #define MAX_OBJECTS  10
  15.  
  16. static char *texttest[6] =
  17.  {"This is a demonstration of the fonts ",
  18.   "available in XLIB. Notice fixed and  ",
  19.   "variabe spaced fonts are supported but",
  20.   "are limited to a maximum of 8 pixels in",
  21.   "width. Height of the characters is    ",
  22.   "ofcourse unlimited..."};
  23.  
  24. typedef struct {
  25.    int X,Y,Width,Height,XDir,YDir,XOtherPage,YOtherPage;
  26.    char far * Image;
  27.    char far * bg;
  28.    char far * bgOtherPage;
  29. } AnimatedObject;
  30.  
  31. AnimatedObject objects[MAX_OBJECTS];
  32. int object_count=0;
  33.  
  34. static char  bm[] = {4,12,
  35.   /* plane 0 */
  36.   2,2,2,2,2,1,1,1,2,1,1,1,2,3,3,1,
  37.   2,0,0,3,2,0,0,3,2,0,0,3,2,0,0,3,
  38.   2,3,3,1,2,1,1,1,2,1,1,1,2,2,2,2,
  39.   /* plane 1 */
  40.   2,2,2,2,1,1,1,1,1,1,1,1,1,3,3,1,
  41.   1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,
  42.   1,3,3,1,1,1,1,1,1,1,1,1,2,2,2,2,
  43.   /* plane 2 */
  44.   2,2,2,2,1,1,1,1,1,1,1,1,1,3,3,1,
  45.   1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,
  46.   1,3,3,1,1,1,1,1,1,1,1,1,2,2,2,2,
  47.   /* plane 3 */
  48.   2,2,2,2,1,1,1,2,1,1,1,2,1,3,3,2,
  49.   3,0,0,2,3,0,0,2,3,0,0,2,3,0,0,2,
  50.   1,3,3,2,1,1,1,2,1,1,1,2,2,2,2,2};
  51.  
  52. static char  bm2[] = {4,12,
  53.    /* plane 0 */
  54.    2,2,2,2,2,4,4,4,2,4,4,4,2,2,2,4,
  55.    2,0,0,2,2,0,0,2,2,0,0,2,2,0,0,2,
  56.    2,2,2,4,2,4,4,4,2,4,4,4,2,2,2,2,
  57.    /* plane 1 */
  58.    2,2,2,2,4,4,4,4,4,4,4,4,4,2,2,4,
  59.    4,0,0,4,4,0,0,4,4,0,0,4,4,0,0,4,
  60.    4,2,2,4,4,4,4,4,4,4,4,4,2,2,2,2,
  61.    /* plane 2 */
  62.    2,2,2,2,4,4,4,4,4,4,4,4,4,2,2,4,
  63.    4,0,0,4,4,0,0,4,4,0,0,4,4,0,0,4,
  64.    4,2,2,4,4,4,4,4,4,4,4,4,2,2,2,2,
  65.    /* plane 2 */
  66.    2,2,2,2,4,4,4,2,4,4,4,2,4,2,2,2,
  67.    2,0,0,2,2,0,0,2,2,0,0,2,2,0,0,2,
  68.    4,2,2,2,4,4,4,2,4,4,4,2,2,2,2,2};
  69.  
  70. int textwindow_x=0,textwindow_y=0;
  71. char far * pal,far * pal2;
  72. char palscrolldir=1;
  73. char far * userfnt1;
  74.  
  75.  
  76.  
  77. void drawtext(int height){
  78.   int i;
  79.   for (i=0;i<6;i++)
  80.     x_printf(textwindow_x+5,50+i*(height+2),VisiblePageOffs,9,texttest[i]);
  81. }
  82.  
  83. /* initialize a new object */
  84. void init_object(int x,int y,int width, int height, int xdir, int ydir,
  85.   char far * image){
  86.   int i;
  87.   objects[object_count].X = objects[object_count].XOtherPage = x;
  88.   objects[object_count].Y = objects[object_count].YOtherPage = y;
  89.   objects[object_count].Width = width;
  90.   objects[object_count].Height = height;
  91.   objects[object_count].XDir = xdir;
  92.   objects[object_count].YDir = ydir;
  93.   objects[object_count].Image = image;
  94.   objects[object_count].bg = (char far *) farmalloc(4*width*height+20);
  95.   objects[object_count].bgOtherPage = (char far *) farmalloc(4*width*height+20);
  96.   x_get_pbm(x,y,(unsigned)width,height,VisiblePageOffs,
  97.     objects[object_count].bg);
  98.   x_get_pbm(x,y,(unsigned)width,height,HiddenPageOffs,
  99.     objects[object_count].bgOtherPage);
  100.   object_count++;
  101. }
  102.  
  103. /* Move the specified object, bouncing at the edges of the screen and
  104.    remembering where the object was before the move for erasing next time */
  105. void MoveObject(AnimatedObject * ObjectToMove) {
  106.    int X, Y;
  107.    char far *cptr;
  108.    X = ObjectToMove->X + ObjectToMove->XDir;
  109.    Y = ObjectToMove->Y + ObjectToMove->YDir;
  110.    if ((X < 0) || (X > (ScrnLogicalPixelWidth-((ObjectToMove->Width)<<2)))) {
  111.       ObjectToMove->XDir = -ObjectToMove->XDir;
  112.       X = ObjectToMove->X + ObjectToMove->XDir;
  113.    }
  114.    if ((Y < 0) || (Y > (ScrnLogicalHeight-ObjectToMove->Height))) {
  115.       ObjectToMove->YDir = -ObjectToMove->YDir;
  116.       Y = ObjectToMove->Y + ObjectToMove->YDir;
  117.    }
  118.    /* Remember previous location for erasing purposes */
  119.    ObjectToMove->XOtherPage = ObjectToMove->X;
  120.    ObjectToMove->YOtherPage = ObjectToMove->Y;
  121.    ObjectToMove->X = X; /* set new location */
  122.    ObjectToMove->Y = Y;
  123.    cptr = ObjectToMove->bg;
  124.    ObjectToMove->bg = ObjectToMove->bgOtherPage;
  125.    ObjectToMove->bgOtherPage = cptr;
  126. }
  127.  
  128. void animate(void){
  129.  int i;
  130.  for(i=object_count-1;i>=0;i--){
  131.   x_put_pbm(objects[i].XOtherPage,objects[i].YOtherPage,
  132.      HiddenPageOffs,objects[i].bgOtherPage);
  133.  }
  134.  for(i=0;i<object_count;i++){
  135.   MoveObject(&objects[i]);
  136.  
  137.   x_get_pbm(objects[i].X,objects[i].Y,
  138.     (unsigned)objects[i].Width,objects[i].Height,HiddenPageOffs,
  139.     objects[i].bg);
  140.   x_put_masked_pbm(objects[i].X,objects[i].Y,HiddenPageOffs,
  141.     objects[i].Image);
  142.  }
  143. }
  144.  
  145. void clear_objects(void){
  146.  int i;
  147.  for(i=object_count-1;i>=0;i--){
  148.   x_put_pbm(objects[i].XOtherPage,objects[i].YOtherPage,
  149.      HiddenPageOffs,objects[i].bgOtherPage);
  150.  }
  151. }
  152.  
  153.  
  154. void textwindow(int Margin){
  155.    int x0=0+Margin;
  156.    int y0=0+Margin;
  157.    int x1=ScrnPhysicalPixelWidth-Margin;
  158.    int y1=ScrnPhysicalHeight-Margin;
  159.    x_rect_fill(x0, y0, x1,y1,VisiblePageOffs,1);
  160.    x_line(x0,y0,x1,y0,2,VisiblePageOffs);
  161.    x_line(x0,y1,x1,y1,2,VisiblePageOffs);
  162.    x_line(x0,y0,x0,y1,2,VisiblePageOffs);
  163.    x_line(x1,y0,x1,y1,2,VisiblePageOffs);
  164.    x_line(x0+2,y0+2,x1-2,y0+2,2,VisiblePageOffs);
  165.    x_line(x0+2,y1-2,x1-2,y1-2,2,VisiblePageOffs);
  166.    x_line(x0+2,y0+2,x0+2,y1-2,2,VisiblePageOffs);
  167.    x_line(x1-2,y0+2,x1-2,y1-2,2,VisiblePageOffs);
  168.    textwindow_x=x0;
  169.    textwindow_y=y0;
  170.  
  171. }
  172.  
  173.  
  174. void wait_for_keypress(void){
  175.   x_show_mouse();
  176.   while(kbhit()) getch();
  177.   palscrolldir^=1;
  178.  
  179.   do {
  180.     x_rot_pal_struc(pal,palscrolldir);
  181.     MouseFrozen=1;
  182.     x_put_pal_struc(pal);
  183.     x_update_mouse();
  184.   } while (!kbhit() && !(MouseButtonStatus==LEFT_PRESSED));
  185.   while(MouseButtonStatus==LEFT_PRESSED);
  186.   while(kbhit()) getch();
  187.  
  188. }
  189.  
  190.  
  191. void exitfunc(void){
  192.   x_mouse_remove();
  193.   x_text_mode();
  194.   printf("Thanks to everyone who assisted in the development of XLIB.\n");
  195.   printf("\nSpecial thanks to Matthew Mackenzie for contributing \n");
  196.   printf("lots of code, documentation and ideas.\n\n");
  197.   printf("If you make any money using this code and you're the generous\n");
  198.   printf("type please send us some, or at least a copy of your program!\n");
  199. }
  200.  
  201. int terminate(void){
  202.   exit(0);
  203. }
  204.  
  205. void intro_1(void){
  206.   x_set_rgb(1,40,40,40); /* BG Gray */
  207.   x_set_rgb(2,63,63,0);  /* Bright Yellow  */
  208.   x_set_rgb(3,63,0,0);   /* Bright Red     */
  209.   x_set_rgb(4,0,63,0);   /* Bright Green   */
  210.   x_set_rgb(5,0,0,63);   /* Bright Blue    */
  211.   x_set_rgb(6,0,0,28);   /* Dark Blue      */
  212.   x_set_rgb(7,0,28,0);   /* Dark Green     */
  213.   x_set_rgb(8,28,0,0);   /* Dark red       */
  214.   x_set_rgb(9,0,0,38);   /* Med Blue       */
  215.  
  216.   textwindow(20);
  217.   x_set_font(1);
  218.   x_printf(textwindow_x+54,textwindow_y+4,VisiblePageOffs,6,"     XLIB Version 5.0");
  219.   x_printf(textwindow_x+53,textwindow_y+3,VisiblePageOffs,2,"     XLIB Version 5.0");
  220.   x_set_font(0);
  221.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"       Not the Unix version");
  222.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,2,"       Not the Unix version");
  223.  
  224.   x_printf(textwindow_x+24,168,VisiblePageOffs,6,"     Press any key to continue");
  225.   x_printf(textwindow_x+23,167,VisiblePageOffs,2,"     Press any key to continue");
  226. }
  227.  
  228. void subsequent_page(void){
  229.   x_hide_mouse();
  230.   textwindow(20);
  231.   x_set_font(1);
  232.   x_printf(textwindow_x+54,textwindow_y+4,VisiblePageOffs,6,"     XLIB Version 5.0");
  233.   x_printf(textwindow_x+53,textwindow_y+3,VisiblePageOffs,2,"     XLIB Version 5.0");
  234.   x_set_font(0);
  235.   x_printf(textwindow_x+24,168,VisiblePageOffs,6,"     Press any key to continue");
  236.   x_printf(textwindow_x+23,167,VisiblePageOffs,2,"     Press any key to continue");
  237. }
  238.  
  239. void load_user_fonts(void){
  240.   FILE *f;
  241.   f=fopen("var6x8.fnt","rb");
  242.   /* read char by char as fread wont read to far pointers in small model */
  243.   { int i; char c;
  244.     for (i=0;i<256*8+4;i++){
  245.       fread(&c,1,1,f);
  246.       *(userfnt1+i)=c;
  247.     }
  248.   }
  249.  
  250.   fclose(f);
  251.  
  252.   x_register_userfont(userfnt1);
  253.  
  254. }
  255.  
  256.  
  257.  
  258. void main(){
  259.   int  i, j, xinc, yinc, Margin;
  260.   char ch;
  261.   WORD curr_x=0, curr_y=0;
  262.  
  263.   pal    = (char far *) farmalloc(256*3);
  264.   pal2   = (char far *) farmalloc(256*3);
  265.   userfnt1 = (char far *) farmalloc(256*16+4);
  266.  
  267.  
  268.   /* INITIALIZE XLIB */
  269.  
  270.   /* we set up Mode X 360x200x256 with a logical width of ~ 500 */
  271.   /* pixels; we actually get 496 due to the fact that the width */
  272.   /* must be divisible by 8                                     */
  273.  
  274.   x_text_mode(); /* make sure VGA is in color mode, if possible */
  275.   x_set_mode(X_MODE_360x200,500);           /* actually is set to 496      */
  276.   x_set_splitscreen(ScrnPhysicalHeight-60); /* split screen 60 pixels high */
  277.   x_set_doublebuffer(220);
  278.   x_text_init();
  279.   x_hide_splitscreen();
  280.   x_mouse_init();
  281.   MouseColor=2;
  282.   atexit(exitfunc);
  283.  
  284.   /* DRAW BACKGROUND LINES */
  285.  
  286.   for(j=0;j<ScrnPhysicalHeight;j++){
  287.    x_line(0,j,ScrnLogicalPixelWidth,j,16+(j%239),VisiblePageOffs);
  288.   }
  289.  
  290.   ctrlbrk(terminate);
  291.   x_get_pal_struc(pal, 240,16);
  292.   load_user_fonts();
  293.  
  294.   intro_1();
  295.   x_set_font(2);
  296.   x_hide_mouse();
  297.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   Hi, folks. This is yet another FREEWARE Mode X");
  298.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " graphics library. It is by no means complete,");
  299.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " but I believe it contains a rich enough set of");
  300.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " functions to achieve its design goal - to be");
  301.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " a game development oriented library for");
  302.   x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " Borland TC/BC/BC++ and TASM programmers.");
  303.  
  304.   x_printf(textwindow_x+5,50+48,VisiblePageOffs,9, "   This library comes with TASM and C sources.");
  305.   x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, " It was inspired by the DDJ Graphics column and");
  306.   x_printf(textwindow_x+5,50+64,VisiblePageOffs,9, " many INTERNET and USENET authors who, unlike the");
  307.   x_printf(textwindow_x+5,50+72,VisiblePageOffs,9, " majority of programmers (you know who you are!),");
  308.   x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, " willingly share their code and ideas with others.");
  309.  
  310.   x_printf(textwindow_x+5,50+88,VisiblePageOffs,9, "   I can't afford, nor do I want, to copyright");
  311.   x_printf(textwindow_x+5,50+96,VisiblePageOffs,9, " this code - but if you use it, some credit would ");
  312.   x_printf(textwindow_x+5,50+104,VisiblePageOffs,9," be appreciated. ");
  313.  
  314.   wait_for_keypress();
  315.  
  316.   subsequent_page();
  317.   x_set_font(0);
  318.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"Supported 256 colour resolutions.");
  319.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"Supported 256 colour resolutions.");
  320.   x_set_font(2);
  321.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " 320x200   Standard for games       ~ 4 pages");
  322.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " 320x240   DDJ Mode X square pixels ~ 3.5 pages");
  323.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " 360x200   My favourite for games   ~ 3 pages  ");
  324.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " 360x240                            ~ 2.8 pages");
  325.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " 320x400                            ~ 2 pages  ");
  326.   x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " 320x480   All subsequent modes support");
  327.   x_printf(textwindow_x+5,50+48,VisiblePageOffs,9, " 360x400     less than two pages.");
  328.   x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, " 360x480");
  329.   x_printf(textwindow_x+5,50+64,VisiblePageOffs,9, " 376x282,360x360,376x308,376x564,256x200,256x240");
  330.   x_printf(textwindow_x+5,50+72,VisiblePageOffs,9, " Phew! and they'll run on all VGA cards and ");
  331.   x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, " monitors (some of the weird ones are best suited");
  332.   x_printf(textwindow_x+5,50+88,VisiblePageOffs,9, " to monitors with both vert & horiz adjustments)");
  333.   x_printf(textwindow_x+5,50+98,VisiblePageOffs,2, "  ");
  334.   x_printf(textwindow_x+5,50+106,VisiblePageOffs,2," Overkill? Maybe!! ");
  335.  
  336.  
  337.   wait_for_keypress();
  338.  
  339.   subsequent_page();
  340.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"      Text display functions.");
  341.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"      Text display functions.");
  342.   x_set_font(2);
  343.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   Several text printing functions are provided.");
  344.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " They support the VGA ROM 8x14 and 8x8 fonts as");
  345.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " well as user-defined fonts (like this 6x8 font).");
  346.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " Furthermore, a function similar to printf is");
  347.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " included which provides formatted text output.");
  348.   x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " User defined fonts may be proportionally spaced");
  349.   x_printf(textwindow_x+5,50+58,VisiblePageOffs,9, " but have a maximum width of 8 pixels.");
  350.  
  351.  
  352.   wait_for_keypress();
  353.  
  354.   subsequent_page();
  355.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    Advanced screen functions.");
  356.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    Advanced screen functions.");
  357.   x_set_font(2);
  358.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   The library supports virtual screens larger");
  359.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " than the physical screen, panning of such");
  360.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " screens, and a split screen option.");
  361.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, "   These functions can be used together or");
  362.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " in isolation, and in the lower resolutions");
  363.   x_printf(textwindow_x+5,50+40,VisiblePageOffs,9, " double buffering can also be accomplished.");
  364.  
  365.   x_rect_fill(0, 0, ScrnPhysicalPixelWidth,60,SplitScrnOffs,5);
  366.   x_line(0,0,ScrnPhysicalPixelWidth,0,2,SplitScrnOffs);
  367.   x_set_font(1);
  368.   x_printf(10,10,SplitScrnOffs,2, " This is a split screen, tops for scores.");
  369.   x_set_font(0);
  370.   for (i=ScrnPhysicalHeight;i>ScrnPhysicalHeight-60;i--){
  371.     x_adjust_splitscreen(i);
  372.   }
  373.   x_printf(10,25,SplitScrnOffs,2, " Even better for scrolling games etc.");
  374.  
  375.   x_cp_vid_rect(0,0,ScrnLogicalPixelWidth,ScrnLogicalHeight,0,0,
  376.         VisiblePageOffs,HiddenPageOffs,
  377.         ScrnLogicalPixelWidth,ScrnLogicalPixelWidth);
  378.  
  379.  
  380.   x_show_mouse();
  381.   wait_for_keypress();
  382.  
  383.   curr_x=curr_y=0;
  384.  
  385.  
  386.   init_object(60,90,4, 12, -1, 1, MK_FP(FP_SEG(bm2),FP_OFF(bm2)));
  387.   init_object(30,30,4, 12, 1, 1, MK_FP(FP_SEG(bm),FP_OFF(bm)));
  388.   init_object(80,120,4, 12, 2, 1, MK_FP(FP_SEG(bm),FP_OFF(bm)));
  389.   init_object(300,200,4, 12, 1, -2, MK_FP(FP_SEG(bm),FP_OFF(bm)));
  390.   init_object(360,30,4, 12, -1, -1, MK_FP(FP_SEG(bm),FP_OFF(bm)));
  391.   init_object(360,10,4, 12, -2, 2, MK_FP(FP_SEG(bm),FP_OFF(bm)));
  392.  
  393.   x_hide_mouse();
  394.  
  395.   while (!kbhit()&& !(MouseButtonStatus==LEFT_PRESSED)){
  396.     animate();
  397.     if (objects[0].X>=curr_x+ScrnPhysicalPixelWidth-32 &&
  398.     curr_x < MaxScrollX) curr_x++;
  399.     else if (objects[0].X < curr_x+16 && curr_x > 0) curr_x--;
  400.     if (objects[0].Y>=curr_y+ScrnPhysicalHeight-92 &&
  401.        curr_y < MaxScrollY) curr_y++;
  402.     else if (objects[0].Y < curr_y+16 && curr_y > 0) curr_y--;
  403.     x_page_flip(curr_x,curr_y);
  404.   }
  405.   while(MouseButtonStatus==LEFT_PRESSED);
  406.   while(kbhit()) getch();
  407.  
  408.   clear_objects();
  409.   x_page_flip(curr_x,curr_y);
  410.  
  411.  
  412.   x_set_start_addr(0,0);
  413.  
  414.  
  415.   for (j=0;j<4;j++){
  416.     x_hide_splitscreen();
  417.     delay(100);
  418.     x_show_splitscreen();
  419.     delay(100);
  420.   }
  421.  
  422.  
  423.   for (i=ScrnPhysicalHeight-60;i<=ScrnPhysicalHeight;i++){
  424.     x_adjust_splitscreen(i);
  425.   }
  426.  
  427.   x_hide_mouse();
  428.   subsequent_page();
  429.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"        Palette functions.");
  430.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"        Palette functions.");
  431.   x_set_font(2);
  432.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   A number of palette manipulation functions");
  433.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " are provided. You have already seen some of");
  434.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " them in action. Another common operation is");
  435.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " palette fading.                     ");
  436.  
  437.   i=0;
  438.   ch=255;
  439.   while (x_cpcontrast_pal_struc(pal, pal2,ch-=2)){
  440.     x_put_pal_struc(pal2);
  441.     x_rot_pal_struc(pal,palscrolldir);
  442.     i++;
  443.   };
  444.   for (j=0;j<i;j++){
  445.     x_cpcontrast_pal_struc(pal, pal2,ch+=2);
  446.     x_put_pal_struc(pal2);
  447.     x_rot_pal_struc(pal,palscrolldir);
  448.   };
  449.   wait_for_keypress();
  450.  
  451.   subsequent_page();
  452.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 3.0 Functions!");
  453.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 3.0 Functions!");
  454.   x_set_font(2);
  455.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " NEW functions not demonstrated here include:");
  456.   x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, "  - RLE data compression");
  457.   x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, "  - FAST compiled masked bitmaps");
  458.   x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, "  - Hardware detection");
  459.  
  460.   x_show_mouse();
  461.   wait_for_keypress();
  462.  
  463.   x_hide_mouse();
  464.   for (i = 0; i < 150; i++) {
  465.       x_circle(0, 0, i, 181 - i, VisiblePageOffs);
  466.       x_circle(360 - i, 0, i, i + 30, VisiblePageOffs);
  467.       x_circle(0, 200 - i, i, i + 30, VisiblePageOffs);
  468.       x_circle(360 - i, 200 - i, i, 181 - i, VisiblePageOffs);
  469.   }
  470.   for (i = 0; i < 100; i++)
  471.     x_filled_circle(80 + i, i, 201 - (i << 1), 30+i, VisiblePageOffs);
  472.   x_show_mouse();
  473.   wait_for_keypress();
  474.  
  475.   subsequent_page();
  476.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 4.0 Functions!");
  477.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 4.0 Functions!");
  478.   x_set_font(2);
  479.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " NEW functions not demonstrated here include:");
  480.   x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, "  - FAST VRAM-based masked bitmaps, including");
  481.   x_printf(textwindow_x+5,50+18,VisiblePageOffs,9, "      support for clipping regions");
  482.   x_printf(textwindow_x+5,50+28,VisiblePageOffs,9, "  - Faster, smaller compiled bitmaps");
  483.   x_printf(textwindow_x+5,50+38,VisiblePageOffs,9, "  - Improved planar bitmap performance and");
  484.   x_printf(textwindow_x+5,50+46,VisiblePageOffs,9, "      additional support for clipping");
  485.   x_printf(textwindow_x+5,50+56,VisiblePageOffs,9, "  - mouse module");
  486.   x_printf(textwindow_x+5,50+66,VisiblePageOffs,9, "  - Detection of math co-processor and mouse");
  487.   x_printf(textwindow_x+5,50+76,VisiblePageOffs,9, "  - Bezier curve module");
  488.   x_printf(textwindow_x+5,50+86,VisiblePageOffs,9, "  - Four new resolutions, including one with");
  489.   x_printf(textwindow_x+5,50+94,VisiblePageOffs,9, "      square pixels (376x282)");
  490.   x_printf(textwindow_x+5,50+104,VisiblePageOffs,9, "  - More bug fixes");
  491.  
  492.   wait_for_keypress();
  493.  
  494.  
  495.   subsequent_page();
  496.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"    NEW Version 5.0 Functions!");
  497.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"    NEW Version 5.0 Functions!");
  498.   x_set_font(2);
  499.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, " - *FAST* filled and clipped triangles ideal for");
  500.   x_printf(textwindow_x+5,50+10,VisiblePageOffs,9, "   3D work. Thanks to S. Dollins for the code.");
  501.   x_printf(textwindow_x+5,50+20,VisiblePageOffs,9, " - Filled and clipped polygons, C++ Compatible");
  502.   x_printf(textwindow_x+5,50+30,VisiblePageOffs,9, " - header files, and of course bug fixes!");
  503.  
  504.   x_show_mouse();
  505.   wait_for_keypress();
  506.  
  507.   randomize();
  508.   x_hide_mouse();
  509.   while(kbhit()) getch();
  510.   palscrolldir^=1;
  511.   do {
  512.     int x0,x1,x2,y0,y1,y2,i;
  513.     i=random(256);
  514.     x0=random(ScrnLogicalPixelWidth);
  515.     x1=random(ScrnLogicalPixelWidth);
  516.     x2=random(ScrnLogicalPixelWidth);
  517.     y0=random(ScrnPhysicalHeight);
  518.     y1=random(ScrnPhysicalHeight);
  519.     y2=random(ScrnPhysicalHeight);
  520.     x_triangle(x0,y0,x1,y1,x2,y2,i,VisiblePageOffs);
  521.   } while (!kbhit() && !(MouseButtonStatus==LEFT_PRESSED));
  522.   while(MouseButtonStatus==LEFT_PRESSED);
  523.   while(kbhit()) getch();
  524.   x_show_mouse();
  525.  
  526.   subsequent_page();
  527.   x_printf(textwindow_x+24,textwindow_y+18,VisiblePageOffs,6,"             PLEASE...");
  528.   x_printf(textwindow_x+23,textwindow_y+17,VisiblePageOffs,3,"             PLEASE...");
  529.   x_set_font(2);
  530.   x_printf(textwindow_x+5,50   ,VisiblePageOffs,9, "   Please mention my name in programs that use XLIB");
  531.   x_printf(textwindow_x+5,50+8 ,VisiblePageOffs,9, " just to make me feel it was worth the effort.");
  532.   x_printf(textwindow_x+5,50+16,VisiblePageOffs,9, " If you have any bug to report please feel free to");
  533.   x_printf(textwindow_x+5,50+24,VisiblePageOffs,9, " mail me a message. Any hints, suggestions and");
  534.   x_printf(textwindow_x+5,50+32,VisiblePageOffs,9, " contributions are welcome and encouraged.");
  535.   x_printf(textwindow_x+5,50+52,VisiblePageOffs,9, " I have contributed this code to the public domain.");
  536.   x_printf(textwindow_x+5,50+60,VisiblePageOffs,9, "    Please respect my wishes and leave it there.");
  537.  
  538.   x_printf(textwindow_x+5,50+80,VisiblePageOffs,9, "   Finally, I hope you all find this stuff useful,");
  539.   x_printf(textwindow_x+5,50+96,VisiblePageOffs,9, " Themie Gouthas - EGG@DSTOS3.DSTO.GOV.AU");
  540.  
  541.   wait_for_keypress();
  542.  
  543.   x_hide_mouse();
  544.  
  545.   x_shift_rect (27, 27, 360-27, 177, 27, 23, VisiblePageOffs);
  546.   x_rect_fill(25, 173, 335, 176, VisiblePageOffs, 1);
  547.   for (i = 0; i < 50; i++) {
  548.     x_shift_rect (27, 26, 360-27, 177 - (i * 3), 27, 23, VisiblePageOffs);
  549.   }
  550. }
  551.  
  552.  
  553.